package com.zprmb.udzt.adapter;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.DexterityBill_Bean;
import com.zprmb.udzt.util.TimeUtils;

public class DexterityBillAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<DexterityBill_Bean> list;
	private String status;
	private DecimalFormat df = new DecimalFormat("###0.00");
	public DexterityBillAdapter(Context context, ArrayList<DexterityBill_Bean> list , String status) {
		this.context = context;
		this.list = list;
		this.status = status;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int arg0) {
		return arg0;
	}

	public long getItemId(int arg0) {
		return arg0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		DexterityBill_Bean db = list.get(position);
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			if (status.equals("IN")) {
				convertView = View.inflate(context, R.layout.v4_item_dexterity_bill_in, null);
				holder.tv_v4_item_dexterity_bill_1 = (TextView) convertView.findViewById(R.id.tv_v4_item_dexterity_bill_1);
				holder.tv_v4_item_dexterity_bill_2 = (TextView) convertView.findViewById(R.id.tv_v4_item_dexterity_bill_2);
				holder.tv_v4_item_dexterity_bill_3 = (TextView) convertView.findViewById(R.id.tv_v4_item_dexterity_bill_3);
			}else {
				convertView = View.inflate(context, R.layout.v4_item_dexterity_bill_out, null);
				holder.tv_v4_item_dexterity_bill_4 = (TextView) convertView.findViewById(R.id.tv_v4_item_dexterity_bill_4);
				holder.tv_v4_item_dexterity_bill_5 = (TextView) convertView.findViewById(R.id.tv_v4_item_dexterity_bill_5);
				holder.tv_v4_item_dexterity_bill_6 = (TextView) convertView.findViewById(R.id.tv_v4_item_dexterity_bill_6);
				holder.tv_v4_item_dexterity_bill_7 = (TextView) convertView.findViewById(R.id.tv_v4_item_dexterity_bill_7);
			}
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (status.equals("IN")) { 
			holder.tv_v4_item_dexterity_bill_1.setText(TimeUtils.formatAllTime(new Date(Long.valueOf(db.recordTime))));
			holder.tv_v4_item_dexterity_bill_2.setText("成功" );
			holder.tv_v4_item_dexterity_bill_3.setText(df.format(Double.parseDouble(db.amount))  );
		}else {
			holder.tv_v4_item_dexterity_bill_4.setText(TimeUtils.formatAllTime(new Date(Long.valueOf(db.applyTime))));
			holder.tv_v4_item_dexterity_bill_5.setText(df.format(Double.parseDouble(db.amount)));
			holder.tv_v4_item_dexterity_bill_6.setText(df.format(Double.parseDouble(db.fee)));
			holder.tv_v4_item_dexterity_bill_7.setText(df.format(Double.parseDouble(db.receivableAmount)));
		}
		return convertView;
	}

	public class ViewHolder {
		TextView tv_v4_item_dexterity_bill_1;
		TextView tv_v4_item_dexterity_bill_2;
		TextView tv_v4_item_dexterity_bill_3;
		TextView tv_v4_item_dexterity_bill_4;
		TextView tv_v4_item_dexterity_bill_5;
		TextView tv_v4_item_dexterity_bill_6;
		TextView tv_v4_item_dexterity_bill_7;
	}
	
}
